<?php
//$tareas = Tarea::model()->activos()->de_entidad($model->id, Tarea::ENTIDAD_TIPO_CAMPANIA)->ordenFechaFin()->findAll();
$tareaProgramadas = CampaniaTareaProgramada::model()->sinAnulados()->findAllByAttributes(array('campania_id' => $model->id));
?>
<div class="widget red">
    <div class="widget-title">
        <h4><i class="icon-tasks"></i> Tareas Programadas</h4>
        <span class="tools">
            <a href="javascript:;" class="icon-chevron-down"></a>
            <a href="javascript:;" class="icon-remove"></a>
        </span>
    </div>
    <div class="widget-body">
        <?php if ($tareaProgramadas): ?>
            <div style='overflow:auto'> 
                <?php
                $this->widget('bootstrap.widgets.TbGridView', array(
                    'id' => 'tareasProgramadas-grid',
                    'afterAjaxUpdate' => "function(id,data){}",
                    'type' => 'striped bordered hover advance',
                    'dataProvider' => new CArrayDataProvider($tareaProgramadas, array('pagination' => array('pageSize' => 5))),
                    'columns' => array(
                        array(
                            'header' => 'Nombre',
                            'name' => 'nombre',
                            'value' => '$data->nombre',
                            'type' => 'raw',
                        ),
                        array(
                            'header' => 'Acción',
                            'name' => 'accion_tipo',
                            'value' => '$data->accion_tipo'
                        ),
                        array(
                            'header' => 'Fecha acción',
                            'name' => 'fecha_accion',
                            'value' => 'Util::FormatDate($data->fecha_accion, "d/m/Y")." ".$data->hora_accion;'
                        ),
                        array(
                            'class' => 'CButtonColumn',
                            'template' => '{update} {delete}',
                            'buttons' => array(
                                'update' => array(
                                    'label' => '<button class="btn btn-primary"><i class="icon-pencil"></i></button>',
                                    'options' => array('title' => 'Actualizar'),
                                    'url' => '"campanias/campaniaTareaProgramada/update/id/".$data->id',
                                    'imageUrl' => false,
                                    'click' => 'js:function(){viewModal($(this).attr("href"),function(){});return false;}',
                                    'visible' => '(Util::checkAccess(array("action_campaniaTareaProgramada_update"))&& $data->estado == Campanias_Constants::TAREA_PROGRAMADA_PENDIENTE)'
                                ),
                                'delete' => array(
                                    'label' => '<button class="btn btn-danger"><i class="icon-trash"></i></button>',
                                    'options' => array('title' => 'Eliminar'),
                                    'url' => 'Yii::app()->createUrl("campanias/campaniaTareaProgramada/delete", array("id"=>$data->id))',
                                    'imageUrl' => false,
                                    'visible' => 'Util::checkAccess(array("action_campaniaTareaProgramada_delete"))',
                                ),
                            ),
                            'htmlOptions' => array(
                                'width' => '140px'
                            )
                        ),
                    ),
                ));
                ?>
            </div>
            <br>

        <?php endif; ?>
        <?php
        $this->widget(
                'bootstrap.widgets.TbButton', array(
            'id' => 'add-tarea',
            'label' => ($tareaProgramadas ? '' : '<br>') . 'Agregar Tarea programada',
            'encodeLabel' => false,
            'icon' => $tareaProgramadas ? 'plus-sign' : 'icon-tasks',
            'htmlOptions' => array(
                'onClick' => 'js:viewModal("campanias/campaniaTareaProgramada/create/campania_id/' . $model->id . '",function(){'
                . 'maskAttributes();})',
                'class' => $tareaProgramadas ? '' : 'empty-portlet',
            ),
                )
        );
        ?>
    </div>
</div>